﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SubSectionInfoList.aspx.cs" Inherits="ExaminationSys.View.Section.SubSectionInfoList" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Register src="SubSectionInfoListEditWindow.ascx" tagname="SubSectionInfoListEdit" tagprefix="uc1"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
      <script type="text/javascript">
          var template = '<span style="color:{0};">{1}</span>';
          var LockRaw = function(value) {
              if (value == false)
                  return Ext.String.format(template, "green", "否");
              else
                  return Ext.String.format(template, "green", "是");

          };

          var templateType = '<span>{0}</span>';
          var SubSectionTypeRaw = function (value) {
              switch (value) {
                  case 1:
                      return Ext.String.format(templateType, "文章");
                  case 2:
                      return Ext.String.format(templateType, "测试");
                  case 3:
                      return Ext.String.format(templateType, "练习");
              }
          };
          var afterItemClick = function(pid, id) {
              var hidden = document.getElementById("SelectNodeParent");
              hidden.value = pid;
              var curhidden = document.getElementById("SelectNode");
              curhidden.value = id;
              return false;
          };
          var moveNode = function (item, oldParent, newParent, index, options) {
//              var buf = [];
//              buf.push("Node = " + item.data.text);
//              buf.push("<br/>");
//              buf.push("Old parent = " + oldParent.data.text + ",old id=" + oldParent.data.id);
//              buf.push("<br/>");
//              buf.push("New parent = " + newParent.data.text + ",new id=" + newParent.data.id);
//              buf.push("<br/>");
//              buf.push("Index = " + index);

//              Ext.Msg.alert("Node droped", buf.join(""));
              X.MoveNode(item.data.id, oldParent.data.id, newParent.data.id);
          };
    </script>
</head>
<body>
    <form id="form1" runat="server">
    
     <input type="hidden" id="SelectNodeParent" runat="server"/>
     <input type="hidden" id="SelectNode" runat="server"/>
     <ext:ResourceManager ID="ResourceManager1" runat="server" DirectMethodNamespace="X"  />


        <ext:Store ID="StoreSubSectionInfo" runat="server" ShowWarningOnFailure="true"  AutoLoad="false" OnReadData="StoreSubSectionInfo_RefreshData">
            <Model>
                <ext:Model ID="SubSectionModel" runat="server" IDProperty="ID">
                    <Fields>
                        <ext:ModelField Name="ID"/>
                        <ext:ModelField Name="SectionID" />
                        <ext:ModelField Name="Name" />
                        <ext:ModelField Name="KnowledgeType" Type="Int" />
                        <ext:ModelField Name="OrderIndex" Type="Int" />
                        <ext:ModelField Name="Status" Type="Int" />
                        <ext:ModelField Name="Lock" Type="Boolean" />
                        <ext:ModelField Name="Content" />
                        <ext:ModelField Name="Opeator" />
                        <ext:ModelField Name="OpeatorTime" Type="Date" />
                    </Fields>
                </ext:Model>
            </Model>            
            <Sorters>
                <ext:DataSorter Property="OrderIndex" Direction="ASC" />
            </Sorters>
            <Listeners>
                <Exception Handler="Ext.MessageBox.alert('Load failed', response.statusText);"></Exception>
            </Listeners>
        </ext:Store>

  <ext:Viewport  runat="server" Layout="BorderLayout">
            <Items>
                  <ext:Panel ID="Panel2" 
				        runat="server"
				        Region="West" 
				        Width="240"  
				        Layout="Fit" 
                        Collapsible="true" 
                        Split="false"
                        Title="知识点(可拖动节点)"
				        Margins="0 0 4 4"
				        Border="false">
                            <Items>
                            <ext:TreePanel 
                                    ID="TreePanelSubSection"
                                    runat="server" 
						            Header="false"
                                    Lines="false" 
                                    CollapseFirst="false"
						            UseArrows="true" 
						            AutoScroll="true" RootVisible="false"  > 
                                    <CustomConfig>
                                        <ext:ConfigItem 
                                            Name="viewConfig"
                                            Value="{
                                                plugins : {
                                                    ptype: 'treeviewdragdrop'
                                                }
                                            }"
                                            Mode="Raw" />
                                    </CustomConfig>
                                         <TopBar>
                                            <ext:Toolbar ID="Toolbar1"  runat="server">
                                                <Items>
                                                    <ext:Button ID="BtnAddNode" runat="server" Text="新增节点" Icon="UserAdd">
                       
                                                    <DirectEvents>
                                                        <Click OnEvent="BtnAddNode_Click" ></Click>                            
                                                    </DirectEvents>
                                                    </ext:Button>
                       
                                                    <ext:Button ID="BtnAddDetailNode" runat="server" Text="新增子节点" Icon="UserAdd">                       
                                                    <DirectEvents>
                                                        <Click OnEvent="BtnAddDetailNode_Click" >
                                                        </Click>                            
                                                    </DirectEvents>
                                                    </ext:Button>
                                                    <ext:Button ID="BtnNodeDelete" runat="server" Text="删除" Icon="UserDelete">
                                                    <Listeners>
                                                        <Click Handler="X.NodeDoConfirm()" />
                                                    </Listeners>
                                                    </ext:Button>                                                   
                                                </Items>
                                            </ext:Toolbar>
                                            </TopBar>
                                    <Store>
							            <ext:TreeStore ID="TreeStore" runat="server" OnReadData="GetNodes">
								            <Proxy>
									            <ext:PageProxy>
										            <RequestConfig Method="GET" Type="Load" />
									            </ext:PageProxy>
								            </Proxy>
								            <Root>
									            <ext:Node NodeID="Root" Expanded="true" />
								            </Root>
							            </ext:TreeStore>
						            </Store>
                                    <DirectEvents>                                    
                                        <ItemClick  OnEvent="NodeClick"  >
                                            <ExtraParams>
                                                   <ext:Parameter Name="Id" Value="record.getId()" Mode="Raw" />
                                            </ExtraParams>
                                        </ItemClick>
                                    </DirectEvents>
                                    <Listeners>
                                     <ItemMove Fn="moveNode" />
                                    </Listeners>
                                </ext:TreePanel>
                            </Items>
                           <Listeners>
                            <AfterRender Handler="this.setTitle('知识点(可拖动节点)');" />
                            <BeforeCollapse Handler="this.setTitle('知识点(可拖动节点)');" />
                            <BeforeExpand Handler="this.setTitle('知识点(可拖动节点)');" />
                           
                               
                        </Listeners>
                        
                     </ext:Panel>

                     <ext:Panel
                     runat="server"
                     Region="Center"
                     Layout="fit" Border="false"  Margins="0 0 4 4"
                     >
                     <Items>
                     <ext:GridPanel 
                                            ID="GridPanelSubSectionInfo" 
                                            runat="server" 
                                            StoreID="StoreSubSectionInfo"             
                                            Header="false"
                                            Border="false"
                                            TrackMouseOver="true"
                                            AutoExpandColumn="Name"  
                                            >
                                         <TopBar>
                                            <ext:Toolbar  runat="server">
                                                <Items>
                                                      <ext:Button ID="BtnAdd" runat="server" Text="新增" Icon="UserAdd">
                                                        <DirectEvents>
                                                            <Click OnEvent="BtnAddDetail_Click"></Click>
                                                        </DirectEvents>
                                                        </ext:Button>
                                                      <ext:Button ID="BtnBatchLock" runat="server" Text="批量锁定" Icon="LockKey">
                                                        <DirectEvents>
                                                            <Click OnEvent="BatchLock_Click"></Click>
                                                        </DirectEvents>
                                                        </ext:Button>
                                                        <ext:Button ID="BtnBatchUnLock" runat="server" Text="解锁" Icon="LockEdit">
                                                        <DirectEvents>
                                                            <Click OnEvent="BatchUnLock_Click"></Click>
                                                        </DirectEvents>
                                                        </ext:Button>
                                                    <ext:Button ID="BtnDelete" runat="server" Text="批量删除" Icon="UserDelete"> 
                                                     <Listeners>
                                                        <Click Handler="X.DoConfirm()" />
                                                    </Listeners>
                                                    </ext:Button>
                                                   <%-- <ext:Button ID="BtnUp" runat="server" Text="上移" Icon="ArrowUp">
                                                    <DirectEvents>
                                                        <Click OnEvent="MoveUp_Click" ></Click>
                                                    </DirectEvents>
                                                    </ext:Button>
                                                    <ext:Button ID="BtnDn" runat="server" Text="下移" Icon="ArrowDown">
                                                    <DirectEvents>
                                                        <Click OnEvent="MoveDn_Click" ></Click>
                                                    </DirectEvents>
                                                    </ext:Button>--%>
                                                    <ext:ToolbarSeparator/>
                                                    <ext:Button ID="返回栏目管理" runat="server" Text="返回栏目管理" Icon="PageBack"> 
                                                        <DirectEvents>
                                                            <Click OnEvent="Btn_GoBack" ></Click>
                                                        </DirectEvents>
                                                    </ext:Button>
                                                </Items>
                                            </ext:Toolbar>
                                            </TopBar>
                                            <SelectionModel> 
                                             <ext:CheckboxSelectionModel  runat="server" Mode="Multi" />
                                            </SelectionModel>
                                            <ColumnModel  runat="server">
			                                    <Columns>
                                                    <ext:Column runat="server" Header="ID" DataIndex="ID" Width="150" Hidden="true" />
                                                    <ext:Column  runat="server" Header="名称" DataIndex="Name" Width="100" />
                                                    <ext:Column   runat="server" Header="类型" DataIndex="KnowledgeType" Width="100">
                                                         <Renderer Fn="SubSectionTypeRaw" />
                                                    </ext:Column>
                                                    <ext:Column  runat="server" Header="锁定" DataIndex="Lock" Width="100">
                                                         <Renderer Fn="LockRaw" />
                                                    </ext:Column>
                                                    <ext:Column  runat="server" Header="排序" DataIndex="OrderIndex" Width="100" />

                                                     <ext:CommandColumn   runat="server" Width="120">
                                                        <Commands >
                                                            <ext:GridCommand Icon="NoteEdit" CommandName="Edit" Text="编辑" />   
                                                            <ext:GridCommand Icon="Delete"  CommandName="Delete" Text="删除" />                         
                                                        </Commands>             
                                                        <DirectEvents>
                                                            <Command OnEvent="Command">
                                                                <ExtraParams>
                                                                     <ext:Parameter Name="Id" Value="record.getId()" Mode="Raw" />
                                                                     <ext:Parameter Name="command" Value="command" Mode="Raw" />
                                                                </ExtraParams>
                                                               <Confirmation BeforeConfirm="if (command=='Edit') return false;" ConfirmRequest="true" Message="是否删除该记录?" Title="提示" />
                                                            </Command>
                                                        </DirectEvents>
                                                    </ext:CommandColumn>
			                                    </Columns>
                                            </ColumnModel>
                                            <View>
                                                <ext:GridView ID="GridView1"  runat="server" />
                                            </View>    

                                        </ext:GridPanel> 
                                        </Items>   
                     </ext:Panel> 
                 
             </Items>
            </ext:Viewport> 

             <ext:Window 
            ID="EditNodeWindow" 
            runat="server" 
            Title="编辑节点"  
            Icon="Application"
            Height="215" 
            Width="350"
            Hidden="true"
            BodyPadding="5"
            Modal="true">
            <Items>
                 <ext:Hidden ID="HiddenParentID" runat="server"></ext:Hidden>
                <ext:TextField ID="TB_ParentNode" AllowBlank="false"  runat="server" FieldLabel="父节点" />
                <ext:TextField ID="TB_NodeText" Name="NewsTitle" runat="server" FieldLabel="节点名称" /> 
                <ext:SelectBox
                    ID="SelectBox_Level"
                    runat="server" 
                    FieldLabel="难度"
                    EmptyText="选择难度...">
                    <Items>
                        <ext:ListItem  Text="初级" Value="1" ></ext:ListItem>
                        <ext:ListItem  Text="中级" Value="2"></ext:ListItem>
                        <ext:ListItem  Text="高级" Value="3"></ext:ListItem>
                    </Items>
                </ext:SelectBox> 
                <ext:SelectBox
                    ID="SelectBox_NodeType"
                    runat="server" 
                    FieldLabel="节点类型"
                    EmptyText="选择节点类型...">
                    <Items>
                        <ext:ListItem  Text="知识点" Value="1" ></ext:ListItem>
                        <ext:ListItem  Text="文件夹" Value="2"></ext:ListItem>
                    </Items>
                </ext:SelectBox>
                <%--<ext:SelectBox
                    ID="SelectBoxSubSectionType"
                    runat="server" 
                    FieldLabel="类型"
                    EmptyText="选择类型...">
                    <Items>
                        <ext:ListItem  Text="文章" Value="1" ></ext:ListItem>
                        <ext:ListItem  Text="测试" Value="2"></ext:ListItem>
                    </Items>
                </ext:SelectBox>--%>
            </Items>
             <Buttons>
                <ext:Button ID="SaveNode" runat="server" Text="保存" Icon="Find">
                    <DirectEvents>
                        <Click OnEvent="SaveNode_Click"  Failure="Ext.MessageBox.alert('process failed', 'Error during ajax event');" >
                        </Click>
                    </DirectEvents>
            
                </ext:Button>
                <ext:Button ID="CancelButton" runat="server" Text="取消" Icon="Cancel">
                    <Listeners>
                         <Click Handler="#{EditNodeWindow}.hide(null);" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:Window>
        
        <uc1:SubSectionInfoListEdit ID="SubSectionInfoListEditWindow" runat="server"  />
    </form>
</body>
</html>
